cmake_minimum_required(VERSION 3.0)

project(Tutorial_cmake LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/INSTALL")

# 版本号
set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 0)

# 配置一个头文件，通过它向源代码中传递一些CMake设置。
configure_file (
  "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
  "${PROJECT_BINARY_DIR}/TutorialConfig.h"
)

# 将二进制文件树添加到包含文件的搜索路径中，这样我们可以找到TutorialConfig.h
include_directories("${PROJECT_BINARY_DIR}")

# 二、引入 MathFunctions 库
# 同时也增加一个选项，我们应该使用我们自己的数学函数吗？
option (USE_MYMATH
        "Use tutorial provided math implementation" ON)

# 添加MathFunctions库吗？
if (USE_MYMATH)
    include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
    add_subdirectory (MathFunctions)
    set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)


# 添加可执行文件
add_executable(${PROJECT_NAME} tutorial.cpp)
target_link_libraries (${PROJECT_NAME}  ${EXTRA_LIBS})

# 三、安装与测试
# 添加安装的目标
install (TARGETS ${PROJECT_NAME} DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
         DESTINATION include)

######## How build #########
# For Windows
# mkdir build & cd build
# cmake -G "Visual Studio 15 2017 Win64" .. // [or Unix : "Unix Makefiles"]
#
# cmake --build . --config Release --verbose
# cmake -P cmake_install.cmake
